/* Copyright (C) 2012  Chris Mueller <ruunsmail@googlemail.com>
 *
 * This file is part of the Liquid Programming Language
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef LIQUID__CONTEXT_H
#define LIQUID__CONTEXT_H

#include "base.h"
#include <stdio.h>

#define LQ_NOLINE -1

struct LqArray;
struct LqScanner;
struct LqNode;
struct LqStack;
struct LqToken;

struct LqLine {
	const byte* begin;
	size_t size;
};


struct LqFile {
    const byte* filename;
    byte* srcbegin;
    struct LqArray* lines;
    int errors;
};


struct LqContext {
    struct LqFile* file;
    
    // Scanning
    byte* stream;
    struct LqToken* current;
    struct LqArray* buffer;
    struct LqQueue* peek;
    
    // Parsing
    struct LqStack* symbols;
    struct LqNode* ast_root;
};


struct LqContext*       lq_context_new(const byte* source, const byte* filename);
void                    lq_context_free(struct LqContext* file);
void			        lq_context_print_status(struct LqContext* context, FILE* out);

void                    lq_error_at(struct LqFile* file, const byte* format, ...);
void                    lq_error_at_line(struct LqFile* file, int line, const byte* format, ...);
void                    lq_notice(const byte* string, ...);

#endif // LIQUID__CONTEXT_H
